import http from "@/api";
import { PageVo, ResultPageData } from "@/api/interface/index";

export namespace Dict {
  export interface DictSelectVo extends PageVo {
    dictCode: string;
    label: string;
    value: string;
  }
  export interface DictSelect {
    label: string;
    value: string;
  }
  export interface DictSearchVo extends PageVo {
    dictCode: string; // 字典码
    tableName: string; // 表名称
  }
  export interface DictOut {
    dictCode: string; // 字典码
    label: string; // 释义列
    value: string; // 值列
  }
  export interface DictInsertVo {
    dictCode: string; // 字典码
    tableName: string; // 表名称
    label: string; // 释义列
    value: string; // 值列
    conditions: string; // 条件
    remark: string; // 备注
  }
  export interface DictUpdateVo {
    id: string; // 字典编号
    tableName: string; // 表名称
    label: string; // 释义列
    value: string; // 值列
    conditions: string; // 条件
    remark: string; // 备注
  }
}
/**
 * 获取字典
 */
export const getDictByCode = (params: Dict.DictSelectVo) => {
  return http.post<ResultPageData<Dict.DictSelect>>("/admin/dict/getDicts", params);
};

export const getDictList = (params: Dict.DictSearchVo) => {
  return http.post<ResultPageData<Dict.DictOut>>("/admin/dict/pageQuery", params);
};

// 根据Id查询角色
export const getDictById = (id: string) => {
  return http.get<Dict.DictOut>("/admin/dict/selectById", { id: id });
};

// 添加字典
export const addDict = (params: Dict.DictInsertVo) => {
  return http.post("/admin/dict/insert", params);
};

// 修改字典
export const updateDict = (params: Dict.DictUpdateVo) => {
  return http.post("/admin/dict/update", params);
};

// 删除字典
export const deleteDict = (id: string) => {
  return http.delete("/admin/dict/delete", { id: id });
};

// 获取在线用户
export const getOnlineUsers = (params: Dict.DictSearchVo) => {
  return http.post<ResultPageData<Dict.DictSelect>>("/admin/getOnlineUser",params);
};